package jman.competition16;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MenuDao {
	public boolean add(Menu menu){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="insert into menu (number,dishname,price,status) values ("+menu.getNumber()+",'"+menu.getDishName()+"',"+menu.getPrice()+",'"+menu.getStatus()+"')";
		flag=d.add(sql);
		d.close();
		return flag;
	}
	public boolean delete(int id){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="delete from menu where id="+id;
		flag=d.delete(sql);
		d.close();
		return flag;
	}
	public boolean updateStatus(int id){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="update menu set status='已上菜' where id="+id;
		flag=d.update(sql);
		d.close();
		return flag;
	}
	public List<Menu> getListForCooker() throws SQLException{
		List<Menu> menuList=new ArrayList<Menu>();
		Dao d=new Dao();
		d.start();
		String sql="select * from menu where status='未上菜'";
		ResultSet rs=d.read(sql);
		while(rs.next()){
			Menu menu=new Menu(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4),rs.getString(5),rs.getString(6));
			menuList.add(menu);
		}
		d.close();
		return menuList;
	}
	public List<Menu> getListForCustomer(int number) throws SQLException{
		List<Menu> menuList=new ArrayList<Menu>();
		Dao d=new Dao();
		d.start();
		String sql="select * from menu where number="+number;
		ResultSet rs=d.read(sql);
		while(rs.next()){
			Menu menu=new Menu(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4),rs.getString(5),rs.getString(6));
			menuList.add(menu);
		}
		d.close();
		return menuList;
	}
}
